﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for clsKetNoi
/// </summary>
public class clsKetNoi
{
	private SqlDataAdapter myAdapter;
    private SqlConnection con;
    public clsKetNoi()
    {
        myAdapter = new SqlDataAdapter();
        //Need add reference to System.Configuration.dll
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["StudentAttendanceConnectionString"].ConnectionString);
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }
    }

    public DataTable executeSelectQuery(string sql)
    {
        SqlCommand command = new SqlCommand(sql, con);
        command.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter adapter = new SqlDataAdapter(command);
        DataTable dt = new DataTable();
        adapter.Fill(dt);
        return dt;
    }
    public DataTable executeSelectQueryProc(string sql, string[] name, object[] value, int Nparameter)
    {
        SqlCommand command = new SqlCommand(sql, con);
        command.CommandType = CommandType.StoredProcedure;
        for (int i = 0; i < Nparameter; i++)
        {
            command.Parameters.AddWithValue(name[i], value[i]);
        }
        SqlDataAdapter adapter = new SqlDataAdapter(command);
        DataTable dt = new DataTable();
        adapter.Fill(dt);
        return dt;
    }
}